package com.tjetc.controller;

import com.github.pagehelper.PageInfo;
import com.tjetc.domain.Clinic;
import com.tjetc.service.ClinicService;
import com.tjetc.service.impl.ClinicServiceImpl;
import com.tjetc.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (clinic)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/clinic")
public class ClinicController {
    /**
     * 服务对象
     */
    @Resource
    private ClinicService clinicService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Clinic selectOne(@RequestParam("id") Integer id) {
        return clinicService.selectByPrimaryKey(id);
    }

    @GetMapping("findByName")
    public Result findByName(@RequestParam("hid") Integer hid, @RequestParam(value = "name",defaultValue = "") String name ) {
        return clinicService.findByName(hid, name);
    }
    @GetMapping("getClinicInfo")
    public Result getClinicInfo(@RequestParam("cid") Integer cid) {
        return clinicService.getClinicInfo(cid);
    }
    @RequestMapping("getAll")
    public Result getAll(@RequestParam("hid")Integer hid) {
        return clinicService.getAll(hid);
    }
    @GetMapping("selAllname")
    public PageInfo<Clinic> selAll(
            @RequestParam(value = "name",defaultValue = "")String name,
            @RequestParam(value = "curPage",defaultValue = "1") Integer curPage,
            @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
            @RequestParam(value = "hid",required = false)Integer hid
    ) {
        return clinicService.selAllname(name, curPage, pageSize,hid);
    }
@GetMapping("delById")
    public Integer delById(@RequestParam("id")Integer id) {
        return clinicService.delById(id);
    }
    @GetMapping("update")
    public Integer update(
            @RequestParam("id") Integer id, @RequestParam("name") String name, @RequestParam("did") Integer did, @RequestParam("h_id") Integer hid, @RequestParam("sg_id") Integer sgid
    ){
        Clinic clinic = new Clinic();
        clinic.setId(id);
        clinic.setName(name);
        clinic.setDid(did);
        clinic.setHId(hid);
        clinic.setSgId(sgid);
        return clinicService.update(clinic);
    }
    @GetMapping("add")
    public Integer add(
            @RequestParam("name") String name, @RequestParam("did") Integer did, @RequestParam("h_id") Integer hid, @RequestParam("sg_id") Integer sgid
            ){
        Clinic clinic = new Clinic();
        clinic.setName(name);
        clinic.setDid(did);
        clinic.setHId(hid);
        clinic.setSgId(sgid);
        return clinicService.add(clinic);
    }
    @GetMapping("getClinicById")
    public Result getClinicById(@RequestParam("id") Integer id) {
        return clinicService.getClinicById(id);
    }
}
